package com.west.imserver.server;

import imserverentity.entity.IChattable;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

import com.west.imserver.runnable.IMClientRunnable;

public class IMServer {
	public static Map<String, IChattable> clients = new HashMap<String, IChattable>();
	public static Map<IChattable, ObjectOutputStream> senders = new HashMap<IChattable, ObjectOutputStream>();
	
	public void start() throws IOException {
		ServerSocket server = new ServerSocket(8888);
		System.out.println("IMServer start");
		while(true) {
			Socket socket = server.accept();
			OutputStream os = socket.getOutputStream();
			ObjectOutputStream oos = new ObjectOutputStream(os);
			new Thread(new IMClientRunnable(socket, oos)).start();
		}
	}
}
